package com.mall.controller;

import com.mall.domain.dto.CartFormDTO;
import com.mall.domain.po.Cart;
import com.mall.domain.vo.CartVO;
import com.mall.service.CartService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购物车相关接口
 */
@RestController
@RequestMapping("/carts")
public class CartController {
    @Resource
    private CartService cartService;

    /**
     * 将商品添加至购物车
     */
    @PostMapping
    public void addItemToCart(@RequestBody CartFormDTO cartFormDTO){
        cartService.addItemToCart(cartFormDTO);
    }

    /**
     * 更新购物车数据
     */
    @PutMapping
    public void updateCart(@RequestBody Cart cart){
        cartService.updateById(cart);
    }

    /**
     * 删除购物车中商品
     */
    @DeleteMapping("/{id}")
    public void deleteCartItem(@PathVariable Long id){
        cartService.removeById(id);
    }

    /**
     * 查询购物车列表
     */
    @GetMapping
    public List<CartVO> queryMyCarts(){
        return cartService.queryMyCarts();
    }

    /**
     * 批量删除购物车中商品
     */
    @DeleteMapping
    public void deleteCartItemByIds(@RequestParam("ids") List<Long> ids){
        cartService.removeByItemIds(ids);
    }

}
